﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Castle.Facilities.TypedFactory;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using Mammoth.Factories;
using Mammoth.Repositories;
using Mammoth.Services;
using Mammoth.ViewModels;

namespace Mammoth.Installers
{
    public class ServiceInstaller : IWindsorInstaller
    {
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            //factories
            container.AddFacility<TypedFactoryFacility>();
            container.Register(Component.For<IRepositoryFactory>().AsFactory());
            container.Register(Component.For<ITypeFactory>()
                .AsFactory(c => c.SelectedWith(new CustomTypedFactoryComponentSelector())));
            container.Register(Component.For<IViewModelFactory>()
                .AsFactory(c => c.SelectedWith(new CustomTypedFactoryComponentSelector())));

            //services
            container.Register(Component.For<IDatabaseConfiguration>()
                .ImplementedBy<MammothConfig>()
                .UsingFactoryMethod(x => MammothConfig.Load()));
            container.Register(Component.For<IAppInitializer>()
                .ImplementedBy<AppInitializer>());
        }
    }
}
